#include<bits/stdc++.h>
using namespace std;
mt19937 Rnd(time(0));
int T = 6,mod = 998244353,n = 1000;
typedef struct{
	int a[1011][1011];
}AD;
AD emt;
void tms(AD& res,AD A,AD B)
{
	res = emt;
	for(int i = 0;i < n;i++)
		for(int j = 0;j < n;j++)
			for(int k = 0;k < n;k++)
				(res.a[i][j] += (1ll * A.a[i][k] * B.a[k][j] % mod)) %= mod;
}
AD A,B,X,C;
int x;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("matrix.in","w",stdout);
	cout << T << "\n";
	while(T--)
	{
		cout << mod << "\n";
		cout << n <<  "\n";
		for(int i = 0;i < n;i++)
			for(int j = 0;j < n;j++)
				A.a[i][j] = Rnd() % mod;
		for(int i = 0;i < n;i++)
			for(int j = 0;j < n;j++)
				B.a[i][j] = Rnd() % mod;
		tms(X,A,B);
		x = (Rnd() & 1);
		cerr << x;
		C = X;
		if(x && mod != 1)
		{
			int i = Rnd() % n,j = Rnd() % n;
			while(C.a[i][j] == X.a[i][j])
				C.a[i][j] = Rnd() % mod;
		}
		for(int i = 0;i < n;i++)
		{
			for(int j = 0;j < n;j++)
				cout << A.a[i][j] << " ";
			cout << "\n";
		}
		for(int i = 0;i < n;i++)
		{
			for(int j = 0;j < n;j++)
				cout << B.a[i][j] << " ";
			cout << "\n";
		}
		for(int i = 0;i < n;i++)
		{
			for(int j = 0;j < n;j++)
				cout << C.a[i][j] << " ";
			cout << "\n";
		}
	}
	return 0;
}
